﻿using System;
using Sproto;
using System.Collections.Generic;


namespace sprotoCsharp
{
	public class TestCaseSprotoTypeDeserialize : TestCaseBase
	{
		public TestCaseSprotoTypeDeserialize ()
		{
		}

		private void test_field() {

//			.Test {
//				var1 0: integer
//				var2 3: string
//				var3 6: boolean
//				var4 9: integer
//				var5 1: integer
//				var6 2: integer 
	//			var7 4: *integer
	//			var8 10: *boolean
	//			var9 11: *string
//			}

			byte[] data = {
				0x0b, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x66, 0x55,
				0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
				0x89, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x03, 0x00,
				0x00, 0x00, 0x61, 0x62, 0x63, 0x39, 0x00, 0x00, 0x00, 0x08,
				0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff,
				0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x44, 0x33, 0x22, 0x11,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x89, 0x99,
				0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x04, 0x00, 0x00, 0x00,
				0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00,
				0x01, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
				0x61, 0x61, 0x62, 0x0c, 0x00, 0x00, 0x00, 0xe4, 0xb8, 0xad,
				0xe6, 0x96, 0x87, 0xe6, 0x98, 0xbe, 0xe7, 0xa4, 0xba, 0x04,
				0x00, 0x00, 0x00, 0x64, 0x64, 0x64, 0x64,
			};

			SprotoTypeDeserialize deserialize = new SprotoTypeDeserialize(data);

			int tag = -1;
			while (-1 != (tag = deserialize.read_tag ())) {
				switch (tag) {
				case 0:
					assert (deserialize.read_integer () == 2);
					break;
				case 3:
					assert (deserialize.read_string () == "abc");
					break;
				case 6:
					assert (deserialize.read_boolean () == true);
					break;
				case 9:
					assert (deserialize.read_integer () == -4);
					break;
				case 1:
					assert (deserialize.read_integer () == 0x112233445566);
					break;
				case 2:
					assert (deserialize.read_integer() == -0x11223344556677);
					break;
				case 4:
					assert (deserialize.read_integer_list(), new Int64[] {11, -2, 0x11223344, 0, 7, 0x112233445566, -0x11223344556677});
					break;
				case 11:
					assert (deserialize.read_string_list(), new string[] {"aab", "中文显示", "dddd"});
					break;
				case 10:
					assert (deserialize.read_boolean_list(), new bool[] {true, false, true, false});
					break;
				default:
					deserialize.read_unknow_data ();
					Console.WriteLine ("unknow field tag: " + tag);
					break;
				}
			}
		}
			
		public override void run() {
			this.test_field();
		}
	}
}

